import random

# print(random.randint(1, 2))

#   函数名称 （元素1，元素2）
# def add(a,b,c):
#     #局部变量
#     info={"状态":"","状态码":"","传入数据":""}
#     if a+b ==c:
#         info["状态"]="OK"
#         info["状态码"]=1
#         info["传入数据"]=[a,b,c]
#     else:
#         info["状态"] = "NO"
#         info["状态码"] = 0
#         info["传入数据"] = [a, b, c]
#     return info
#
# #全局变量
# a=int(input(">>>>"))
# b=int(input(">>>>"))
# c=int(input(">>>>"))
# num=add(a,b,c)
#
# def erorr(a,b):
#     c=a+b
#     print("纠错成功！！！正确的结果为:{}".format(c))
#     x=add(a,b,c)
#     return x
#
# if num["状态码"]==0:
#     print("您输入的内容有误，是否需要纠正")
#     o=input(">>>>>>")
#     if o=="是":
#         print(erorr(a,b))
#     else:
#         print(num)
# else:
# #     print(num)
# def add(a,b,c):
#     info={"状态":"","状态号":"","传入数据":""}
#     if a+b==c:
#         info["状态"]="ok"
#         info["状态号"]=1
#         info["传入数据"]=[a,b,c]
#     else:
#         info["状态"] = "no"
#         info["状态号"] = 0
#         info["传入数据"] = [a,b,c]
#     return info
# a=int(input("<<<<<<<"))
# b=int(input("<<<<<<<"))
# c=int(input("<<<<<<<"))
# num=add(a,b,c)
# def erorr(a,b):
#     c=a+b
#     print("纠错成功，正确结果为：{}".format(c))
#     x=add(a,b,c)
#     return x
# if num["状态号"]==0:
#     print("您输入的结果有错，是否需要纠错")
#     o=input("<<<<<<<")
#     if o=="是":
#         print(erorr(a,b))
#     else:
#         print(num)
# else:
#     print(num)
import random

print("***************************")
print("\t  中国工商银行")
print("\t\t1、开户")
print("\t\t2、存钱")
print("\t\t3、取钱")
print("\t\t4、转账")
print("\t\t5、查询")
print("\t\t6、Buy")
print("***************************")
bank={}
bank_name="中国工商银行"
#用户
def user_info():
    account=random.randint(10000000,99999999)
    username=input("请输入您的用户")
    password=input("请输入您的密码")
    country=input("\t\t请输入您的国家")
    province=input("\t\t请输入您的省份")
    street=input("\t\t请输入您的街道")
    door=input("\t\t请输入您的门牌号")
    x=bank_add(account, username, password, country, province, street, door,)
    if x==1:
        print("开户成功，一下是您的信息")
        info='''
        ------%s------
        账号:%s
        用户名:%s
        密码:******
        国家:%s
        省份:%s
        街道:%s
        门牌号:%s
        余额:%s
        '''
        print(info %(bank_name,account, username,country, province, street, door,bank[account]["money"]))
    elif x==2:
        print("账户已存在")
    elif x==3:
        print("数据库已满")



def bank_add(account,username,password,country,province,street,door):
    if len(bank)>=100:
        return 3
    elif account in bank:
        return 2
    else:
        bank[account]={
            "username":username,
            "password":password,
            "country":country,
            "province":province,
            "street":street,
            "door":door,
            "money":0,
            "bankname":bank_name
        }
    return 1
#存钱
def save_money():
    account=int(input("请输入您的账号"))
    money=int(input("请输入存款金额"))
    if account in bank:
        bank[account]["money"]+=money
        return True
    else:
        return False
def cun ():
    c=save_money()
    if c==True:
        print("存款成功")
    elif c==False:
        print("存款失败，账户不存在")


#取钱
def Withdraw_money():
    account = int(input("请输入您的账号"))
    password = input("请输入账户密码")
    money=int(input("请输入取款金额"))
    if account not in bank:
        return 1
    elif password not in bank[account]["password"]:
        return 2
    elif bank[account]["money"]>=money:
        bank[account]["money"]-=money
        return 0
    else:
        return 3
def qu():
    q=Withdraw_money()
    if q==0:
        print("取钱成功")
    elif q==1:
        print("账号不存在")
    elif q==2:
        print("密码不对")
    elif q==3:
        print("钱不够")

#转账
def transfer_accounts():
    account=int(input("请输入转出的账号"))
    accounts=int(input("请输入转入的账号"))
    password=input("请输入转出账号的密码")
    money=int(input("请输入转出的金额"))
    if account and accounts not in bank:
        return 1
    elif password not in bank["password"]:
        return 2
    elif money<bank[account]["money"]:
        bank[account]["money"]-=money
        bank[accounts]["money"]+=money
        return 0
    else:
        return 3

def zhuan():
    z=transfer_accounts()
    if z==1:
        print("账号不存在")
    elif z==2:
        print("密码错误")
    elif z==3:
        print("金额不足，转账失败")
    elif z==0:
        print("转账成功")
# 查询
def query():
    account=int(input("请输入查询账户"))
    password=input("请输入账户密码")
    if account not in bank:
        print("用户不存在")
    elif password !=bank[account]["password"]:
        print("密码不正确")
    else:
        info = '''
                ------%s-----
                当前账号:%s
                用户名:%s
                密码:******
                余额:%s
                国家:%s
                省份:%s
                街道:%s
                门牌号:%s
                开户行:%s
                '''
        print(info % (bank_name, account, bank[account]["username"], bank[account]["money"], bank[account]["country"],
                      bank[account]["province"], bank[account]["street"], bank[account]["door"], bank_name))


# def cha():
#     ch=query()
#     account = int(input("请输入查询账户"))
#     if ch==1:
#         print("用户不存在")
#     elif ch==2:
#         print("密码不正确")
#     elif ch==0:
#         info='''
#         ------%s-----
#         当前账号:%s
#         用户名:%s
#         密码:******
#         余额:%s
#         街道:%s
#         门牌号:%s
#         开户行:%s
#         '''
#         print(info%(bank_name,account,bank[account]["username"],bank[account]["money"],bank[account]["country"],bank[account]["province"],bank[account]["street"],bank[account]["door"],bank_name))














while True:
    index=input("请选择业务")
    if index=="1":
        print("开户")
        user_info()
        print(bank_name)
    elif index=="2":
        print("存钱")
        cun()
    elif index=="3":
        print("取钱")
        qu()
    elif index=="4":
        print("转账")
        zhuan()
    elif index=="5":
        print("查询")
        query()
    elif index=="6":
        print("Buy")
        bank
    else:
        print("您输入内容有误")








